import numpy as np

import myplt.plt_utils
import myplt.plt_utils as c

# 生成一组随机数字
# data = [random.randint(1, 100) for _ in range(20)]
filename = "D:\\data.csv"
data = np.genfromtxt(filename, delimiter=' ', dtype=float)

# 初始化峰值和谷值
peaks = []
troughs = []

# 遍历数据并找到峰值和谷值
for i in range(1, len(data) - 1):
    if data[i] > data[i - 1] and data[i] > data[i + 1]:
        if len(peaks) == 0:
            peaks.append(i)
        else:
            troughs.append(i - 1)
            peaks.append(i)
    elif data[i] < data[i - 1] and data[i] < data[i + 1]:
        if len(troughs) == 0:
            troughs.append(i)
        else:
            peaks.append(i - 1)
            troughs.append(i)

        # 输出结果
print("随机数字：", data)
print("波峰：", peaks)
print("波谷：", troughs)

x = range(0, len(data))
myplt.plt_utils.do_line(x, data, '日期', '股价', '股价走势图')
